# Status line
source-file "${HOME}/.config/tmux/tmux.theme.conf"

# Below tmux settings does the following
# - Setting the correct terminal for tmux
# - IDK how, but this allows strikethrough text with highlights
set -g default-terminal "${TERM}"
# 1. Fix some color issue inside the shell like autocompletion grey background
#    - Fix color issue inside with alacritty
# 2. Add colors to underscore/undercurl inside neovim
set -ga terminal-features '*:clipboard:strikethrough:usstyle:RGB'

# Sane scrolling
# TODO: make sure this works in OSX
# set -g terminal-overrides 'xterm*:smcup@:rmcup@'

set -g mouse on # enable mouse mode (tmux 2.1 and above)

set -g mode-keys vi # vi is good
set -g status-keys emacs # emacs key bindings in tmux command prompt

set -g base-index 1         # starting window numbered 1
set -g pane-base-index 1    # starting pane numbered 1
set -g renumber-windows on  # renumber windows when one is closed

set -g set-titles on # enable dynamic title
set -g set-titles-string '#S #I::#W' # dynamic title format

set -s escape-time 0 # address vim mode switching delay (http://superuser.com/a/252717/65504)
set -g history-limit 50000 # increase scrollback buffer size
set -g display-time 3000 # display messages for 3 seconds
set -g focus-events on # focus events enabled for terminals that support them
setw -g aggressive-resize on # super useful when using "grouped sessions" and multi-monitor setup

# by default there is no way to go direct into visual block mode, so I have to improvise
bind-key -T copy-mode-vi C-v send -X begin-selection \; send -X rectangle-toggle

# by default, pressing SPACE starts visual mode
bind-key -T copy-mode-vi v send -X begin-selection

# pressing i should exit vi-mode
bind-key -T copy-mode-vi i send -X cancel

# Press Alt-c to create new window
bind-key -n M-c new-window

# source .tmux.conf as suggested in `man tmux`
bind R source-file "${HOME}/.config/tmux/tmux.conf" \; display-message 'Config reloaded!'

# Open a project in new window
bind o display-popup -T " Projects " -h 20 -w 50 -E '$SHELL -c $HOME/.config/tmux/scripts/finder'

# Open manual or --help of a command
bind h display-popup -T " Help " -h 3 -w 25 -E '$SHELL -c $HOME/.config/tmux/scripts/manner'

# Tmux tilish
set -g @tilish-navigator 'on'
set -g @tilish-default 'tiled'

# Better mouse mode
set -g @emulate-scroll-for-no-mouse-alternate-buffer "on"
set -g @scroll-speed-num-lines-per-scroll 2
set -g @scroll-down-exit-copy-mode "off"

# Tmux yank
set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default

# Tmux Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'jabirali/tmux-tilish'
set -g @plugin 'nhdaly/tmux-better-mouse-mode'

# tmux-plugins/tmux-pain-control

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run -b "${HOME}/.tmux/plugins/tpm/tpm"
